package com.junlong0716.enjoylearning.adapter

import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.htxcsoft.corelibrary.glide.GlideUtils
import com.junlong0716.enjoylearning.R
import com.junlong0716.enjoylearning.constant.NetConstant
import com.junlong0716.enjoylearning.entity.ChannelMultipleItemEntity
import com.junlong0716.enjoylearning.entity.ChannelMultipleItemEntity.Companion.ITEM_TYPE_AUDIO
import com.junlong0716.enjoylearning.entity.ChannelMultipleItemEntity.Companion.ITEM_TYPE_DOCUMENT
import com.junlong0716.enjoylearning.entity.ChannelMultipleItemEntity.Companion.ITEM_TYPE_VIDEO
import java.text.SimpleDateFormat

/**
 *@author: 巴黎没有摩天轮Li
 *@description:
 *@date: Created in 下午9:40 2018/5/22
 *@modified by:
 */
class ChannelListAdapter(data: ArrayList<ChannelMultipleItemEntity>) : BaseMultiItemQuickAdapter<ChannelMultipleItemEntity, BaseViewHolder>(data) {
    init {
        addItemType(ChannelMultipleItemEntity.ITEM_TYPE_VIDEO, R.layout.child_item_find_commend_video_layout)
        addItemType(ChannelMultipleItemEntity.ITEM_TYPE_AUDIO, R.layout.child_item_find_commend_audio_layout)
        addItemType(ChannelMultipleItemEntity.ITEM_TYPE_DOCUMENT, R.layout.child_item_find_commend_document_layout)
    }

    override fun convert(helper: BaseViewHolder?, item: ChannelMultipleItemEntity?) {
        when (helper!!.itemViewType) {
            ITEM_TYPE_VIDEO -> {
                GlideUtils.showImageFade(mContext, NetConstant.REQUEST_SOURCE + item!!.coverImg, helper.getView(R.id.riv_video_img))
                helper.setText(R.id.tv_topic_name, item.knowledgeTitle)
                helper.setText(R.id.tv_topic_description, item.authorName + "|" + TimeUtils.millis2String(item.createDate, SimpleDateFormat("MM-dd")))

            }
            ITEM_TYPE_AUDIO -> {
                GlideUtils.showImage(mContext, NetConstant.REQUEST_SOURCE + item!!.coverImg, helper.getView(R.id.civ_audio))
                helper.setText(R.id.tv_topic_name, item.knowledgeTitle)
                helper.setText(R.id.tv_topic_description, item.authorName + "|" + TimeUtils.millis2String(item.createDate).substring(5, 10))
            }
            ITEM_TYPE_DOCUMENT -> {
                helper.setText(R.id.tv_title, item!!.knowledgeTitle)
                helper.setText(R.id.tv_content, item.knowledgeDescribe)
                helper.setText(R.id.tv_writer, item.authorName)
                helper.setText(R.id.tv_date, TimeUtils.millis2String(item.createDate, SimpleDateFormat("MM-dd")))
            }
        }

        if (item!!.userName != "") {
            helper.setVisible(R.id.tv_share_user, true)
            helper.setText(R.id.tv_share_user, "分享人：${item.userName}")
        }
    }
}